package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.naming.Name;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper mapper;


    @Override
    public List<User> getAll() {
        return mapper.selectList(null);
    }

    @Override
    public void deletById(Integer id) {

        mapper.deleteById(id);
    }

    @Override
    public void upda1(User user) {

       mapper.updateById(user);
    }

    @Override
    public User gteUserId(User user) {

       return mapper.selectById(user);
    }

    @Override
    public User getByNs(User user) {
//根据用户传递的对象中不为空的属性充当 where条件


        QueryWrapper<User> query=new QueryWrapper();
        query.eq("name", user.getName())
                .eq("sex", user.getSex());
        return  mapper.selectOne(query);
    }

    @Override
    public List<User> getName(String name) {

        QueryWrapper<User> query=new QueryWrapper();

        query.like("Name",  name);

        return mapper.selectList(query);
    }

    @Override
    public void deleteUserById(Integer id) {
    mapper.deleteById(id);
    }

    @Override
    public void saveUser(User user) {
        mapper.insert(user);
    }

    @Override
    public void saveUser2(User user) {
        mapper.insert(user);
    }
      //用户更新
    @Override
    public void updateUser(User user) {
          //根据对象中不为空的数据当做set 条件，id当做where条件
        mapper.updateById(user);
    }


}
